package in.hitmedia.test.bitswise;

public class BitwiseOps 
{

	public static void main(String args[])
	{
		int a = 61;
		int b = 0x5;
		
		System.out.println(a);
		print (a);
		//print2 (a);
		print(setBit(a, 1));
		print(unsetBit(a, 3));
		print(d(2));
		print(e(3));
	}
	
	
	//Addition -~x = x + 1
	static int d(int i)
	{
		return -~i;
		
	}
	
	//Addition -~x = x + 1
	static int e(int i)
	{
		return ~-i;
		
	}	
	
	//set bit at ith position startwith 0th bit  
	static int setBit(int n, int pos)
	{
		return (n | (1 << pos));
	}
	
	static int unsetBit(int n, int pos)
	{
		return (n & ~(1 << pos));
	}
	
	
	static void print(int n)
	{
		for (int i = 31; i >=0 ; --i)
		{
			System.out.print(n >> i & 1 );
		}
		System.out.println();
	}
	
	//prints in reverse order
	static void print2(int n)
	{
		for (; n > 0 ; n >>= 1)
		{
			System.out.print(n & 1 );
		}
		System.out.println();
	}
	
}
